<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
class Catetype_model extends CI_Model {
    
    function __construct()
    {
        // Call the Model constructor
        parent::__construct();
        $this->load->database(); 
    }
    function show_allcategory($num,$offset){
    	$this->load->database();
    	$this->db->order_by("id", "desc");
    	$query=$this->db->get('tbcatecontent',$num,$offset);
    	if ($query->num_rows() > 0)
    	{
    		return $query->result();
    	}
    	return $query->result();
    }
    function _show_cateogry_by_type($id){
    	$this->load->database();
    	$this->db->where("typeid", $id);
    	$query=$this->db->get('tbcatecontent');
    	if ($query->num_rows() > 0)
    	{
    		return $query->result();
    	}
    	return $query->result();
    }
    
    function showllcate(){
    	$this->load->database();
    	$this->db->order_by("id", "desc");
    	$query=$this->db->get('tbcatecontent');
    	if ($query->num_rows() > 0)
    	{
    		return $query->result();
    	}
    	return $query->result();
    }
    
    function showallcategoryhome(){
    	$this->load->database();
    	$this->db->order_by("id", "desc");
    	$this->db->where('active',1);
    	$query=$this->db->get('tbcatecontent');
    	if ($query->num_rows() > 0)
    	{
    		return $query->result();
    	}
    	return $query->result();
    }
    function totalcate(){
    	$this->load->database();
    	return $this->db->count_all('tbcatecontent');
    }
    function showdetailscate($id){
    	$this->load->database();
    	$this->db->where('id',$id);
    	$query=$this->db->get('tbcatecontent');
    	if ($query->num_rows() > 0)
    	{
    		return $query->result();
    	}
    	return $query->result();
    }
    
    function add_categorytype($typeid,$catename,$cateroot,$active){
    	$this->load->database();
    	$data = array(
    			'typeid'=>$typeid,
    			'catename'=>$catename,
    			'cateroot'=>$cateroot,
    			'active'=>$active,
    	);
    	$this->db->insert('tbcatecontent', $data);
    }
    
    function edit_categorytype($id,$typeid,$catename,$cateroot,$active){
    	$this->load->database();
    	$data = array(
    			'typeid'=>$typeid,
    			'catename'=>$catename,
    			'cateroot'=>$cateroot,
    			'active'=>$active,
    	);
    	$this->db->where('id', $id);
    	$this->db->update('tbcatecontent', $data);
    }
    
    function changestatus($id=null,$active=null){
    	$this->load->database();
    	$data = array('active'=>$active);
    	$this->db->where('id',$id);
    	$this->db->update('tbcatecontent',$data);
    }
    
    function changestatustype($id=null,$active=null){
    	$this->load->database();
    	$data = array('active'=>$active);
    	$this->db->where('id',$id);
    	$this->db->update('tbtype',$data);
    }
    
    function del_category($id){
    	$this->load->database();
    	$this->db->where('id', $id);
    	$this->db->delete('tbcatecontent');
    }
    
    function _showalltype(){
    	$this->load->database();
    	$this->db->order_by("id", "desc");
    	$query=$this->db->get('tbtype');
    	if ($query->num_rows() > 0)
    	{
    		return $query->result();
    	}
    	return $query->result();
    }
    function _detailtype($id){
    	$this->load->database();
    	$this->db->where('id',$id);
    	$query=$this->db->get('tbtype');
    	if ($query->num_rows() > 0)
    	{
    		return $query->result();
    	}
    	return $query->result();
    }
    function add_type($nametype){
    	$this->load->database();
    	$data = array(
    			'nametype'=>$nametype, 
    	);
    	$this->db->insert('tbtype', $data);
    }
    
    function del_type($id){
    	$this->load->database();
    	$this->db->where('id', $id);
    	$this->db->delete('tbtype');
    }
    
    function edit_type($id,$name){
    	$this->load->database();
    	$data = array( 
    			'nametype'=>$name, 
    	);
    	$this->db->where('id', $id);
    	$this->db->update('tbtype', $data);
    }
    
    
}
    